package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.Worker;
import com.ruoyi.manage.service.IWorkerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社工Controller
 * 
 * @author Admin
 * @date 2025-09-06
 */
@RestController
@RequestMapping("/manage/worker")
public class WorkerController extends BaseController
{
    @Autowired
    private IWorkerService workerService;

    /**
     * 查询社工列表
     */
    @PreAuthorize("@ss.hasPermi('manage:worker:list')")
    @GetMapping("/list")
    public TableDataInfo list(Worker worker)
    {
        startPage();
        List<Worker> list = workerService.selectWorkerList(worker);
        return getDataTable(list);
    }

    /**
     * 导出社工列表
     */
    @PreAuthorize("@ss.hasPermi('manage:worker:export')")
    @Log(title = "社工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Worker worker)
    {
        List<Worker> list = workerService.selectWorkerList(worker);
        ExcelUtil<Worker> util = new ExcelUtil<Worker>(Worker.class);
        util.exportExcel(response, list, "社工数据");
    }

    /**
     * 获取社工详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:worker:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workerService.selectWorkerById(id));
    }

    /**
     * 新增社工
     */
    @PreAuthorize("@ss.hasPermi('manage:worker:add')")
    @Log(title = "社工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Worker worker)
    {
        return toAjax(workerService.insertWorker(worker));
    }

    /**
     * 修改社工
     */
    @PreAuthorize("@ss.hasPermi('manage:worker:edit')")
    @Log(title = "社工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Worker worker)
    {
        return toAjax(workerService.updateWorker(worker));
    }

    /**
     * 删除社工
     */
    @PreAuthorize("@ss.hasPermi('manage:worker:remove')")
    @Log(title = "社工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workerService.deleteWorkerByIds(ids));
    }
}
